class ClienteController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ clienteList: Cliente.list( params ) ]
    }

    def show = {
        def cliente = Cliente.get( params.id )

        if(!cliente) {
            flash.message = "Cliente not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ cliente : cliente ] }
    }

    def delete = {
        def cliente = Cliente.get( params.id )
        if(cliente) {
            cliente.delete()
            flash.message = "Cliente ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Cliente not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def cliente = Cliente.get( params.id )

        if(!cliente) {
            flash.message = "Cliente not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ cliente : cliente ]
        }
    }

    def update = {
        def cliente = Cliente.get( params.id )
        if(cliente) {
            cliente.properties = params
            if(!cliente.hasErrors() && cliente.save()) {
                flash.message = "Cliente ${params.id} updated"
                redirect(action:show,id:cliente.id)
            }
            else {
                render(view:'edit',model:[cliente:cliente])
            }
        }
        else {
            flash.message = "Cliente not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def cliente = new Cliente()
        cliente.properties = params
        return ['cliente':cliente]
    }

    def save = {
        def cliente = new Cliente(params)
        if(!cliente.hasErrors() && cliente.save()) {
            flash.message = "Cliente ${cliente.id} created"
            redirect(action:show,id:cliente.id)
        }
        else {
            render(view:'create',model:[cliente:cliente])
        }
    }
}
